package com.example.jpademo.conf;

import com.example.jpademo.utils.SnowFlake;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;
import java.util.Random;
import java.util.UUID;

@Slf4j
public class RandomIdGenerator implements IdentifierGenerator {
    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        log.warn("此ID策略可能发生冲突");
//        return new Random().nextInt(5)*100000;
        return SnowFlake.getId();
    }
}
